package crazy.memory;

import java.io.InputStream;


public class Account
{
	private String accountNo;
	private double balance;
	
	public Account()
	{
	}
	
	public Account(String accountNo, double balance)
	{
		this.accountNo = accountNo;
		this.balance = balance;

	}
	
	public double getBalance()
	{
		return this.balance;
	}
	
	public synchronized  void draw(double drawAmount)
	{
		if (balance >= drawAmount)
		{
			System.out.println(Thread.currentThread().getName() + "get money ok:" + drawAmount);
			balance = balance - drawAmount;
			System.out.println("new balance:"+balance);
		}
		else 
		{
			System.out.println(Thread.currentThread().getName()+"fail");
		}
	}
	
	@Override
	public int hashCode()
	{
		return accountNo.hashCode();
	}
	
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj != null && obj.getClass() == Account.class)
		{
			Account target = (Account) obj;
			return target.accountNo.equals(accountNo);
		}
		return false;
	}
}
